import { HashRouter,BrowserRouter,Route,Routes,Link } from "react-router-dom";

import Layout from "@/pages/layout/index";
import Login from "@/pages/login/index";
import Dashboard from "@/pages/dashboard/index";
// import Good from "@/pages/good/goodForm";
import Good from "@/pages/good/goodList";
import User from "@/pages/user/index";
import { asyncRoutes } from "./pages/index.jsx"

import { Provider } from "react-redux";
import store from "@/store/index";

function createRoutes(accessRoutes) {
    let result = [];

    accessRoutes.forEach(route => {
        if (route.path && route.element) {
            result.push(
                <Route key={route.key} path={route.path} element={route.element}></Route>
            )
        }
        if (route.children) {
            route.children.forEach(route => {
                result.push(
                    <Route key={route.key} path={route.path} element={route.element}></Route>
                )
            })
        }
    })

    return result;
}




// 在Raect中，组件名必须大写
function App() {
    return (
        <HashRouter>
            {/* <Link to="/">首页</Link>
            <Link to="/login">登录</Link> */}
            <Provider store={store}>
                    <Routes >
                    <Route path="/" element={<Layout />}>
                    {/* <Route path="/dashboard" element={<Dashboard />}></Route> 
                    <Route path="/good" element={<Good />}></Route> 
                    <Route path="/user" element={<User />}></Route>  */}
                    {
                        createRoutes(asyncRoutes)
                    }
                    </Route>
                    <Route path="/login" element={<Login />}></Route>
            </Routes>
            </Provider>
           
        </HashRouter>
    );
}
export default App;
